﻿using LiteBlog.Common.Entities;
using LiteBlog.Components.Contracts;
using LiteBlog.IoC;
using LiteBlog.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Web.Mvc;

namespace LiteBlog.Controllers.Tests
{
    [TestClass]
    public class ControllerTests<T> where T: LiteBlog.Controllers.Contracts.IController
    {
        protected T _controller;
        protected Settings _settings;

        [TestInitialize]
        public virtual void InitTest()
        {
            _controller = IoCContainer.Resolve<T>();
            _controller.ResolveComponents();
            _settings = new Settings();
            var settingsMock = Mock.Get<ISettingsComp>(_controller.SettingsComponent);
            settingsMock.Setup(se => se.Load())
                        .Returns(_settings);
        }

        [TestCleanup]
        public void Cleanup()
        {
            _controller.UserModel = new UserModel(null, false);
        }

        [TestMethod]
        public void ControllerIsNotNull()
        {
            Assert.IsNotNull(_controller);
        }

        [TestMethod]
        public void SettingsComponentIsNotNull()
        {
            Assert.IsNotNull(_controller.SettingsComponent);
        }


        protected object GetModel(ActionResult actionResult)
        {
            var viewResult = actionResult as ViewResultBase;
            return viewResult.Model;
        }
    }
}
